/*
 * @lc app=leetcode.cn id=643 lang=java
 *
 * [643] 子数组最大平均数 I
 */

// @lc code=start
class Solution {
    public double findMaxAverage(int[] nums, int k) {
        int n=nums.length;
        int[] preSum=new int[n+1];
        for(int i=0;i<n;i++){
            preSum[i+1]=preSum[i]+nums[i];
        }
        double max=Double.NEGATIVE_INFINITY;
        for(int i=k-1;i<n;i++){
            max=Math.max(preSum[i+1]-preSum[i-k+1], max);
        }
        return max/k;
    }
}
// @lc code=end

